<template>
  <a-card class="j-inner-table-wrapper" :bordered="false">

    <!-- 查询区域 begin -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="耳标号">
          <j-search-select-tag v-model="queryParam.earLabel" placeholder="请选择耳标号" dict="rpm_reg_prgancyregistry,distinct ear_label,ear_label"/>
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="产犊日期">
              <j-date-limit  class="query-group-cust" v-model="queryParam.calvingDate_begin" placeholder="请选择开始时间"/>
          <span class="query-group-split-cust"></span>
              <j-date-limit  class="query-group-cust" v-model="queryParam.calvingDate_end" placeholder="请选择结束时间"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="产犊类型">
            <j-dict-select-tag v-model="queryParam.calvingType" placeholder="请选择产犊类型" dictCode="claving_type"/>
              </a-form-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="产犊描述">
          <j-dict-select-tag v-model="queryParam.calvingDescription" placeholder="请选择产犊描述" dictCode="calving_desc_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="产犊数">
             <a-input v-model="queryParam.calvingNumber" placeholder="请输入产犊数"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="产犊难易度">
          <j-dict-select-tag v-model="queryParam.calvingDifficulty" placeholder="请选择产犊难易度" dictCode="calving_diff_level"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="是否见胎">
             <a-input v-model="queryParam.isFetusvisible" placeholder="请输入是否见胎"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="操作员">
          <j-dict-select-tag v-model="queryParam.operatorId" placeholder="请选择操作员" dictCode="sys_user,realname,username"/>
            </a-form-item>
          </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons table-operator">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" @click="searchReset">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                <span>{{ toggleSearchStatus ? '收起' : '展开' }}</span>
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域 end -->

    <!-- 操作按钮区域 begin -->
    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('产犊登记记录')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            <span>删除</span>
          </a-menu-item>
        </a-menu>
        <a-button>
          <span>批量操作</span>
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>
    <!-- 操作按钮区域 end -->

    <!-- table区域 begin -->
    <div>

      <a-alert type="info" showIcon style="margin-bottom: 16px;">
        <template slot="message">
          <span>已选择</span>
          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </template>
      </a-alert>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :expandedRowKeys="expandedRowKeys"
        :rowSelection="{selectedRowKeys, onChange: onSelectChange}"
        @expand="handleExpand"
        @change="handleTableChange"
      >

        <!-- 内嵌table区域 begin -->
        <template slot="expandedRowRender" slot-scope="record">
<!--          <a-tabs tabPosition="top">-->
<!--            <a-tab-pane tab="犊牛管理关系表" key="rpmRegCalfmanagerelation" forceRender>-->
              <rpm-reg-calfmanagerelation-sub-table :record="record"/>
<!--            </a-tab-pane>-->
<!--          </a-tabs>-->
        </template>
        <!-- 内嵌table区域 end -->

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <div style="font-size: 12px;font-style: italic;">
            <span v-if="!text">无图片</span>
            <img v-else :src="getImgView(text)" alt="" style="max-width:80px;height:25px;"/>
          </div>
        </template>

        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            ghost
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)"
          >
            <span>下载</span>
          </a-button>
        </template>

        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">
              <span>更多 <a-icon type="down"/></span>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>

        </template>

      </a-table>
    </div>
    <!-- table区域 end -->

    <!-- 表单区域 -->
    <rpm-reg-calvingregistry-modal ref="modalForm" @ok="modalFormOk"/>

  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import RpmRegCalvingregistryModal from './modules/RpmRegCalvingregistryModal'
  import RpmRegCalfmanagerelationSubTable from './subTables/RpmRegCalfmanagerelationSubTable'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import JDate from '@/components/jeecg/JDate.vue'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'

  export default {
    name: 'RpmRegCalvingregistryList',
    mixins: [JeecgListMixin],
    components: {
      RpmRegCalvingregistryModal,
      RpmRegCalfmanagerelationSubTable,
      JDate,
      JDictSelectTag,
    },
    data() {
      return {
        description: '产犊登记记录列表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: (t, r, index) => parseInt(index) + 1
          },
          {
            title: '耳标号',
            align: 'center',
            sorter: true,
            dataIndex: 'earLabel_dictText'
          },
          {
            title: '产犊日期',
            align: 'center',
            sorter: true,
            dataIndex: 'calvingDate',
          },
          {
            title: '产犊类型',
            align: 'center',
            sorter: true,
            dataIndex: 'calvingType_dictText'
          },
          {
            title: '产犊描述',
            align: 'center',
            sorter: true,
            dataIndex: 'calvingDescription_dictText'
          },
          {
            title: '产犊数',
            align: 'center',
            sorter: true,
            dataIndex: 'calvingNumber',
          },
          {
            title: '产犊难易度',
            align: 'center',
            sorter: true,
            dataIndex: 'calvingDifficulty_dictText'
          },
          {
            title: '是否见胎',
            align: 'center',
            sorter: true,
            dataIndex: 'isFetusvisible',
            customRender: (text) => (!text ? "" : (text == "Y" ? "是" : "否"))
          },
          {
            title: '助产/难产原因',
            align: 'center',
            dataIndex: 'causeofMidwiferyOrDystocia',
          },
          {
            title: '操作员',
            align: 'center',
            sorter: true,
            dataIndex: 'operatorId_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            width:147,
            scopedSlots: { customRender: 'action' },
          },
        ],
        // 字典选项
        dictOptions: {},
        // 展开的行test
        expandedRowKeys: [],
        url: {
          list: '/rpm/rpmRegCalvingregistry/list',
          delete: '/rpm/rpmRegCalvingregistry/delete',
          deleteBatch: '/rpm/rpmRegCalvingregistry/deleteBatch',
          exportXlsUrl: '/rpm/rpmRegCalvingregistry/exportXls',
          importExcelUrl: '/rpm/rpmRegCalvingregistry/importExcel',
        },
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl() {
        return window._CONFIG['domianURL'] + this.url.importExcelUrl
      }
    },
    methods: {

      initDictConfig() {
      },

      handleExpand(expanded, record) {
        this.expandedRowKeys = []
        if (expanded === true) {
          this.expandedRowKeys.push(record.id)
        }
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'earLabel',text:'耳标号',dictCode:'rpm_reg_prgancyregistry,ear_label,ear_label'})
        fieldList.push({type:'datetime',value:'calvingDate',text:'产犊日期'})
        fieldList.push({type:'string',value:'calvingType',text:'产犊类型',dictCode:'claving_type'})
        fieldList.push({type:'string',value:'calvingDescription',text:'产犊描述',dictCode:'calving_desc_type'})
        fieldList.push({type:'int',value:'calvingNumber',text:'产犊数',dictCode:''})
        fieldList.push({type:'string',value:'calvingDifficulty',text:'产犊难易度',dictCode:'calving_diff_level'})
        fieldList.push({type:'switch',value:'isFetusvisible',text:'是否见胎'})
     //   fieldList.push({type:'string',value:'causeofMidwiferyOrDystocia',text:'助产/难产原因',dictCode:''})
        fieldList.push({type:'string',value:'operatorId',text:'操作员',dictCode:'sys_user,realname,username'})

        this.superFieldList = fieldList
      },
    }
  }
</script>
<style lang="less" scoped>
  @import '~@assets/less/common.less';
</style>